﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Automobile.service.Model;
using Automobile.service.BLL;
using System.Data;

namespace Automobile.service.UI
{
    public partial class UpdateBlitem : System.Web.UI.Page
    {       
        WareHoseBll wbll = new WareHoseBll();
        ProductBll pbll = new ProductBll();
        BlitemBll bll = new BlitemBll();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["fid"] != null)
                {
                    LoadData();
                    LoadData1();
                    LoadPro();
                    LoadType();
                }
            }
        }
        private void LoadType()
        {
            this.DropDownList3.DataSource = bll.Blitem_type();
            this.DropDownList3.DataValueField = "Blitem_type_Id";
            this.DropDownList3.DataTextField = "Blitem_type_name";
            this.DropDownList3.DataBind();
        }

        private void LoadPro()
        {
            this.DropDownList2.DataSource = pbll.Product();
            this.DropDownList2.DataValueField = "Product_Id";
            this.DropDownList2.DataTextField = "Product_Name";
            this.DropDownList2.DataBind();
        }

        private void LoadData1()
        {
            this.DropDownList1.DataSource = wbll.WareHose();
            this.DropDownList1.DataValueField = "WareHose_Id";
            this.DropDownList1.DataTextField = "WareHose_Name";
            this.DropDownList1.DataBind();

        }
        private void LoadData()
        {
            this.TextBox2.Text = Request.QueryString["fid"].ToString();

            DataTable dt = bll.GetBlitem(this.TextBox2.Text);
            if (dt != null)
            {
                this.TextBox3.Text = dt.Rows[0][1].ToString();
                this.DropDownList1.SelectedValue = dt.Rows[0][2].ToString();
                this.TextBox5.Text = dt.Rows[0][3].ToString();
                this.TextBox6.Text = dt.Rows[0][4].ToString();
                this.TextBox7.Text = dt.Rows[0][5].ToString();
                this.TextBox8.Text = dt.Rows[0][6].ToString();
                this.DropDownList2.SelectedValue = dt.Rows[0][7].ToString();
                this.DropDownList3.SelectedValue = dt.Rows[0][8].ToString();
            }
        }

        protected void BtnAdd(object sender, EventArgs e)
        {
            BlitemModel b = new BlitemModel();
            b.Blitem_Id =Convert.ToInt32(this.TextBox2.Text);
            b.Blitem_Etc = this.TextBox3.Text.ToString();
            b.WareHose_Id = Convert.ToInt32(DropDownList1.SelectedValue);
            b.Blitem_date = Convert.ToDateTime(this.TextBox5.Text);
            b.Blitem_num = Convert.ToInt32(this.TextBox6.Text);
            b.Blitem_Rownum = Convert.ToInt32(this.TextBox7.Text);
            b.Blitem_Stock_num = Convert.ToInt32(this.TextBox8.Text);
            b.Product_Id = Convert.ToInt32(DropDownList2.SelectedValue);
            b.Blitem_Type_Id = Convert.ToInt32(DropDownList3.SelectedValue);
            if (bll.UpdateBlitem(b) > 0)
            {
                Response.Write("<script>alert('修改成功');location.href='Blitem.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('修改失败!');</script>");
            }
        }

        protected void BtnBack(object sender, EventArgs e)
        {
            Response.Redirect("Blitem.aspx");
        }
    }
}